import os
import re
from os import path

from setuptools import setup, find_packages

from xinhou_openai_framework.core.config.ConfigHandler import ConfigHandler
from xinhou_openai_framework.utils.ObjDictUtil import ObjectDict
from xinhou_openai_framework.utils.StrUtil import StrUtil

read_stream_config = ConfigHandler.read_yaml(os.path.join(os.getcwd(), "application.yml"))
base_ctx = ObjectDict.from_dict(read_stream_config)

base_path = path.abspath(path.dirname(__file__))
with open(path.join(base_path, 'requirements.txt'), 'r', encoding='utf-8') as f:
    all_reqs = f.read().split('\n')

with open(path.join(base_path, 'README.md'), 'r', encoding='utf-8') as f:
    long_description = f.read()

install_requires = [x.strip() for x in all_reqs if 'git+' not in x]

# 定义一个函数，用于判断是否需要排除指定的包
def get_exclude_package(package_name):
    # 需要排除的目录列表
    excluded_dirs = ['apps', 'common', 'deploy', 'logs', 'static']
    # 判断包名是否在排除的目录列表中
    return any(package_name.startswith(dir_name) for dir_name in excluded_dirs)


# 查找包时排除指定的目录
excluded_packages = [package for package in find_packages() if get_exclude_package(package)]

setup(
    name=StrUtil.replace(base_ctx.application.name,'-','_'),
    version=base_ctx.application.version,
    author=base_ctx.application.author,
    author_email=base_ctx.application.email,
    description='XINHOU-OPENAI-FRAMEWORK基础框架，主要提供应用服务的底层支持技术代码支撑，通过该框架可以快速实现单服务、微服务、消息队列、ORM的快速开发！',
    long_description=long_description,
    long_description_content_type='text/markdown',
    url='http://gitlab.xinhouai.com/openai/xinhou-openai-framework.git',
    include_package_data=True,
    packages=find_packages(exclude=excluded_packages),
    install_requires=install_requires,
    classifiers=[
        "Development Status :: 5 - Production/Stable",
        "Intended Audience :: Developers",
        "License :: Other/Proprietary License",
        "Programming Language :: Python :: 3",
        "Operating System :: MacOS",
        "Topic :: Software Development :: Libraries :: Python Modules",
    ],
    python_requires=">=3.9"
)
